/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package party;

/**
 *
 * @author houfukude
 */
//编译环境：MyEclipse
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class party {

	public static int input(){//输入数字字符

		BufferedReader  bf= new  BufferedReader(new  InputStreamReader(System.in));//输入数据

		try{

            return Integer.parseInt(bf.readLine());//将数据转换为整型
	    }catch(Exception e){ //捕捉异常，并进行异常处理

		    System.out.print("输入错误，请重新输入: ");//输入错误，需要重新输入
            return input();
	    }
    }

	public static void index( int n ){//执行算法
		int  num;//party总人数
		int  count = 0;//总共进行了count轮数据删除
		boolean  bool = true;
		num = n;
        int  []select = new  int[num];

		for( int i = 0; i < num; i ++ ){
			select[i] = i+1;
		}
		while( num != 1){
			count ++;
			bool = true;

			System.out.print("第"+ count + "轮删除的人员编号为: ");
			for( int i = 0; i < num; i ++){
				if( (i+1)%2 != 0 ){
					System.out.print(" " + select[i]);
					select[i] = 0;
				}
			}
			System.out.println();

			while( bool ){
				bool = false;
				for( int i = 0; i < num-1; i ++){
					if( select[i] == 0 ){
				 	    select[i] = select[i+1];
				 	    select[i+1] = 0;
				    }
				}
				if( select[num-2] == 0 && select[num-1] == 0 ){
					num = num - 2;
				}
				else{
					      num --;
				}
				for( int i = 0; i < num; i ++){
					if( select[i] == 0 ){
						 bool = true;
						 break;
					}
				}
			}
		}
		System.out.println("\n幸运编号: " + select[0]);
	}

	public static void main(String[] args) {
		int  n;//party总人数

		do{
	    	  System.out.println();
	          System.out.print("输入参加人数: ");
			  n = input();

	          if( n != 0 ){
	        	  index( n );
	          }
	          else{
	        	  System.out.println();
                  System.exit(0);
	          }
	      }while (n != 0);
	}
}